#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>

using namespace std;
class Solution {
public:
    string decodeString(string s) {
        stack<string> st;
        stack<int> num;
        st.push("");
        int i = 0, n = s.size();
        while (i < n)
        {
            if (s[i] >= '0' && s[i] <= '9')
            {
                int tmp = 0;
                while (i < n && s[i] >= '0' && s[i] <= '9') tmp = tmp * 10 + (s[i++] - '0');
                num.push(tmp);
            }
            else if (s[i] == '[')
            {
                i++;
                string tmp;
                while (s[i] <= 'z' && s[i] >= 'a') tmp += s[i++];
                st.push(tmp);
            }
            else if (s[i] == ']')
            {
                string tmp = st.top();
                st.pop();
                int k = num.top();
                num.pop();
                while (k)
                {
                    st.top() += tmp;
                    k--;
                }
                i++;
            }
            else
            {
                string tmp;
                while (i < n && s[i] <= 'z' && s[i] >= 'a') tmp += s[i++];
                st.top() += tmp;
            }
        }
        return st.top();
    }
};
int main() {
    return 0;
}